package com.ygqh.baby.service.impl;
import java.util.List;

import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.YgPages;
import  com.ygqh.baby.mapper.YgPagesMapper;
import  com.ygqh.baby.service.YgPagesService;

import  org.springframework.util.Assert;

import java.util.Arrays;

import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.YgPagesExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class YgPagesServiceImpl implements YgPagesService{
	
	@Autowired
	private YgPagesMapper ygPagesMapper;
	
	@Override
	public List<YgPages> find() {
		YgPagesExample example = new YgPagesExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygPagesMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		YgPagesExample example = new YgPagesExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygPagesMapper.countByExample(example);
	}

	@Override
	public YgPages findById(Long id) {
		return ygPagesMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(YgPages ygPages) {
		return ygPagesMapper.insertSelective(ygPages);
	}

	@Override
	public int update(YgPages ygPages) {
		return ygPagesMapper.updateByPrimaryKeySelective(ygPages);
	}
	
	@Override
	public long saveAndReturnId(YgPages ygPages) {
		ygPagesMapper.insertSelective(ygPages);
		return ygPages.getId();
	}

	@Override
	public ResultSet<YgPages> search(QueryInfo queryInfo,String q) {
		List<YgPages>  list =  ygPagesMapper.selectSuper(queryInfo, q);
		int count = ygPagesMapper.countSuper(q);
		ResultSet<YgPages> resultSet = new ResultSet<YgPages>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		YgPagesExample example = new YgPagesExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		YgPages record = new YgPages();
		record.setStatus(DataStatus.Delete);

		return ygPagesMapper.updateByExampleSelective(record, example);
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(YgPages ygPages) {
		int r = 0;
		if(ygPages.getId() != null) {
			r = this.update(ygPages);
		}else {
			r = this.save(ygPages);
		}
		return r;
	}

	@Override
	public String findAdvertisingPage() {
	
		String content=ygPagesMapper.getAdPagesContent();		
		return content;
	}
	
}

